package br.fmapn.web.mb;

import java.util.ArrayList;
import java.util.List;

import javax.faces.event.ActionEvent;
import javax.faces.model.SelectItem;

import br.fmapn.process.entities.BusinessProcess;
import br.fmapn.register.BusinessProcessServicesRemote;
import br.fmapn.web.util.GerenciadorLookup;

/**
 * 
 * @author heitor
 *
 */
public class MBManterProcesso {

	private BusinessProcess businessProcess;
	
	public BusinessProcess getBusinessProcess() {
		return businessProcess;
	}

	public void setBusinessProcess(BusinessProcess businessProcess) {
		this.businessProcess = businessProcess;
	}



	private List<BusinessProcess> businessProcesses;
	private BusinessProcessServicesRemote businessProcessServices;

	public MBManterProcesso() {
		this.businessProcess = new BusinessProcess();
		//this.businessOperation = new BusinessOperation();
		this.businessProcesses = new ArrayList<BusinessProcess>();
		
		
		businessProcessServices = GerenciadorLookup.obterBusinessProcessServices();
	}

	public void cadastrarProcesso(ActionEvent evento) {

		businessProcessServices.saveBusinessProcess(businessProcess);
		businessProcess = new BusinessProcess();
	}
	
	
	public List<BusinessProcess> getBusinessProcesses() {
		this.businessProcesses = businessProcessServices.getBusinessProcesses();
		return businessProcesses;
	}



	public void setBusinessProcesses(List<BusinessProcess> businessProcesses) {
		this.businessProcesses = businessProcesses;
	}
	
	public List<SelectItem> getAllCombo(){
		List<SelectItem> lista = new ArrayList<SelectItem>();
		for(BusinessProcess bp : getBusinessProcesses()){
			SelectItem item = new SelectItem(bp.getId(), bp.getName());
			lista.add(item);
		}
		return lista;
	}
}
